home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / champbas.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  144 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. static int gfxbank;
  15.  
  16.  
  17. /***************************************************************************
  18.  
  19.   Convert the color PROMs into a more useable format.
  20.  
  21.   Pac Man has a 16 bytes palette PROM and a 128 bytes color lookup table PROM.
  22.  
  23.   Pengo has a 32 bytes palette PROM and a 256 bytes color lookup table PROM
  24.   (actually that's 512 bytes, but the high address bit is grounded).
  25.  
  26.   The palette PROM is connected to the RGB output this way:
  27.  
  28.   bit 7 -- 220 ohm resistor  -- BLUE
  29.         -- 470 ohm resistor  -- BLUE
  30.         -- 220 ohm resistor  -- GREEN
  31.         -- 470 ohm resistor  -- GREEN
  32.         -- 1  kohm resistor  -- GREEN
  33.         -- 220 ohm resistor  -- RED
  34.         -- 470 ohm resistor  -- RED
  35.   bit 0 -- 1  kohm resistor  -- RED
  36.  
  37. ***************************************************************************/
  38. void champbas_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  39. {
  40.     int i;
  41.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  42.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  43.  
  44.  
  45.     for (i = 0;i < Machine->drv->total_colors;i++)
  46.     {
  47.         int bit0,bit1,bit2;
  48.  
  49.  
  50.         /* red component */
  51.         bit0 = (*color_prom >> 0) & 0x01;
  52.         bit1 = (*color_prom >> 1) & 0x01;
  53.         bit2 = (*color_prom >> 2) & 0x01;
  54.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  55.         /* green component */
  56.         bit0 = (*color_prom >> 3) & 0x01;
  57.         bit1 = (*color_prom >> 4) & 0x01;
  58.         bit2 = (*color_prom >> 5) & 0x01;
  59.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  60.         /* blue component */
  61.         bit0 = 0;
  62.         bit1 = (*color_prom >> 6) & 0x01;
  63.         bit2 = (*color_prom >> 7) & 0x01;
  64.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  65.  
  66.         color_prom++;
  67.     }
  68.  
  69.     /* color_prom now points to the beginning of the lookup table */
  70.  
  71.     /* TODO: there are 32 colors in the palette, but we are suing only 16 */
  72.     /* the only difference between the two banks is color #14, grey instead of green */
  73.  
  74.     /* character lookup table */
  75.     /* sprites use the same color lookup table as characters */
  76.     for (i = 0;i < TOTAL_COLORS(0);i++)
  77.         COLOR(0,i) = (*(color_prom++) & 0x0f);
  78. }
  79.  
  80.  
  81.  
  82. WRITE_HANDLER( champbas_gfxbank_w )
  83. {
  84.     if (gfxbank != (data & 1))
  85.     {
  86.         gfxbank = data & 1;
  87.         memset(dirtybuffer,1,videoram_size);
  88.     }
  89. }
  90.  
  91.  
  92. /***************************************************************************
  93.  
  94.   Draw the game screen in the given osd_bitmap.
  95.   Do NOT call osd_update_display() from this function, it will be called by
  96.   the main emulation engine.
  97.  
  98. ***************************************************************************/
  99. void champbas_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  100. {
  101.     int offs;
  102.  
  103.  
  104.     /* for every character in the Video RAM, check if it has been modified */
  105.     /* since last time and update it accordingly. */
  106.     for (offs = videoram_size - 1;offs >= 0;offs--)
  107.     {
  108.         if (dirtybuffer[offs])
  109.         {
  110.             int sx,sy;
  111.  
  112.  
  113.             dirtybuffer[offs] = 0;
  114.  
  115.             sx = 8 * (offs % 32);
  116.             sy = 8 * (offs / 32);
  117.  
  118.             drawgfx(tmpbitmap,Machine->gfx[0 + gfxbank],
  119.                     videoram[offs],
  120.                     (colorram[offs] & 0x1f) + 32,
  121.                     0,0,
  122.                     sx,sy,
  123.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  124.         }
  125.     }
  126.  
  127.  
  128.     /* copy the character mapped graphics */
  129.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  130.  
  131.  
  132.     /* Draw the sprites. Note that it is important to draw them exactly in this */
  133.     /* order, to have the correct priorities. */
  134.     for (offs = spriteram_size - 2;offs >= 0;offs -= 2)
  135.     {
  136.         drawgfx(bitmap,Machine->gfx[2 + gfxbank],
  137.                 spriteram[offs] >> 2,
  138.                 spriteram[offs + 1],
  139.                 spriteram[offs] & 1,spriteram[offs] & 2,
  140.                 ((256+16 - spriteram_2[offs + 1]) & 0xff) - 16,spriteram_2[offs] - 16,
  141.                 &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  142.     }
  143. }
  144.